﻿using Exepack;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;

namespace ExepackTests
{
	/// <summary>
	/// Tests for ExeCompressor
	/// </summary>
	[TestClass]
	public class ExeCompressorTest
	{
		public TestContext TestContext { get; set; }

		[TestMethod]
		public void ExeCompressor_GenerateLoaderEmitsValidAssembly()
		{
			using (var c = new ExeCompressor())
			{
				var options = CompressionOptions.Create(GetType().Assembly.Location);
				var asmName = options.OutputAssemblyName = "MyExepackTestsLoader";
				var exeName = options.OutputFileName = "TestLoader.exe";

				// file is saved
				c.GenerateLoader(options, new string[0]);
				Assert.IsTrue(File.Exists(exeName));

				// check if assembly is valid and its name is derived from current assembly name
				var asmInfo = new AssemblyInformation(exeName);
				Assert.IsTrue(asmInfo.AsmName.Name == asmName);
			}
		}

		[TestMethod]
		public void ExeCompressor_RandomNamesAreNotEmptyAndRandom()
		{
			using (var c = new ExeCompressor())
			{
				var n1 = c.GenerateRandomName();
				Assert.IsFalse(string.IsNullOrEmpty(n1));

				var n2 = c.GenerateRandomName();
				Assert.IsFalse(string.IsNullOrEmpty(n2));

				Assert.AreNotEqual(n1, n2);
			}
		}
	}
}
